package org.liulinlin.sejw.db;

import java.sql.*;

/**
 * 对应数据库中的订舱计划
 * @author kodylau
 *
 */
public class OrderPlan { //extends DataAccessServiceImpl {
	private String id;
	private ShipSchedule shipSchedule;
	private java.sql.Date startTime;
	private String startTimeString;
	private java.sql.Date endTime;
	private String endTimeString;
	private java.sql.Date cancelTime;
	private String cancelTimeString;
	private int totalBox;
	private int bigBox;
	private BoxConstraints boxConstraints;
	
	public OrderPlan() {
		
	}
	public OrderPlan(String id) {		
		DBConnectionManager connMgr = DBConnectionManager.getInstance();
		
		Connection con = connMgr.getConnection("shipping_export");
		if (con == null) {
			System.out.println("不能获得数据库连接");
			return;
		}
		Statement stmt = null;
		ResultSet rs = null;
		
		try {
			stmt = con.createStatement();
			rs = stmt.executeQuery("select * from OrderPlan where OrderPlan_ID = '" + id + "'");
			
			rs.next();
			this.id = id;
			shipSchedule = new ShipSchedule(rs.getString("Scd_ID"));
			startTime = rs.getDate("OrderPlan_StartTime");
			startTimeString = startTime.toString();
			endTime = rs.getDate("OrderPlan_EndTime");
			endTimeString = endTime.toString();
			cancelTime = rs.getDate("OrderPlan_CancelTime");
			cancelTimeString = cancelTime.toString();
			totalBox = rs.getInt("OrderPlan_TotalBox");
			bigBox = rs.getInt("OrderPlan_BigBox");
			if (rs.getInt("BC_ID") != -1) {
				boxConstraints = new BoxConstraints(rs.getInt("BC_ID"));
			}
			
			stmt.close();
			rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		connMgr.freeConnection("shipping_export", con);
		connMgr.release();
	}
	
	public void setID(String id) {
		this.id = id;
	}
	public void setShipSchedule(ShipSchedule shipSchedule) {
		this.shipSchedule = shipSchedule;
	}
	public void setStartTime(java.sql.Date startTime) {
		this.startTime = startTime;
	}
	public void setStartTimeString(String startTimeString) {
		this.startTimeString = startTimeString;
	}
	public void setEndTime(java.sql.Date endTime) {
		this.endTime = endTime;
	}
	public void setEndTimeString(String endTimeString) {
		this.endTimeString = endTimeString;
	}
	public void setCancelTime(java.sql.Date cancelTime) {
		this.cancelTime = cancelTime;
	}
	public void setCancelTimeString(String cancelTimeString) {
		this.cancelTimeString = cancelTimeString;
	}
	public void setTotalBox(int totalBox) {
		this.totalBox = totalBox;
	}
	public void setBigBox(int bigBox) {
		this.bigBox = bigBox;
	}
	public void setBoxConstraints(BoxConstraints boxConstraints) {
		this.boxConstraints = boxConstraints;
	}
	
	public String getID() {
		return id;
	}
	public ShipSchedule getShipSchedule() {
		return shipSchedule;
	}
	public java.sql.Date getStartTime() {
		return startTime;
	}
	public String getStartTimeString() {
		return startTimeString;
	}
	public java.sql.Date getEndTime() {
		return endTime;
	}
	public String getEndTimeString() {
		return endTimeString;
	}
	public java.sql.Date getCancelTime() {
		return cancelTime;
	}
	public String getCancelTimeString() {
		return cancelTimeString;
	}
	public int getTotalBox() {
		return totalBox;
	}
	public int getBigBox() {
		return bigBox;
	}
	public BoxConstraints getBoxConstraints() {
		return boxConstraints;
	}
}

